package com.qiantu.api.entity;

import java.util.ArrayList;
import java.util.List;
public class ElecPriceBean {
    public String houseSerialNo;
    public int calculateType;//1.固定电价；2.峰谷电价
    public float price;
    public List<StageConfigurationBean> stageConfigurations;

    /**
     * 添加新电价时间段
     */
    public void addNewStage(){
        if (stageConfigurations == null){
            stageConfigurations = new ArrayList<>();
        }
        StageConfigurationBean newBean = new StageConfigurationBean(stageConfigurations.size()+1);
        stageConfigurations.add(newBean);
    }

    public void addNewStage(int count){
        for (int i = 0; i < count; i++) {
            addNewStage();
        }
    }

    public void removeStagePosition(int position){
        if (stageConfigurations == null || stageConfigurations.size()<=position) return;
        stageConfigurations.remove(position);
        for (int i = position; i < stageConfigurations.size(); i++) {
            stageConfigurations.get(i).section--;
        }
    }

    public static class StageConfigurationBean {
        public int section;//分段 排序标识
        public int startHour;
        public int startMinute;
        public int endtHour;
        public int endMinute;
        public float price;

        public StageConfigurationBean(int section) {
            this.section = section;
        }

        public String getTimeStr(){
            if (startHour == 0 && startMinute==0 && endtHour ==0 && endMinute==0){
                return "";
            }
            StringBuffer buffer = new StringBuffer();
            if (startHour<10){
                buffer.append("0").append(startHour);
            }else {
                buffer.append(startHour);
            }
            buffer.append(":");
            if (startMinute<10){
                buffer.append("0").append(startMinute);
            }else {
                buffer.append(startMinute);
            }
            buffer.append("~");
            if (endtHour<10){
                buffer.append("0").append(endtHour);
            }else {
                buffer.append(endtHour);
            }
            buffer.append(":");
            if (endMinute<10){
                buffer.append("0").append(endMinute);
            }else {
                buffer.append(endMinute);
            }
            return buffer.toString();
        }
    }
}
